gdk/x11: Add gdk_x11_device_get_id()
authorCarlos Garnacho <carlosg@gnome.org>
Thu, 14 Jul 2011 15:43:59 +0000 (17:43 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Fri, 15 Jul 2011 16:14:38 +0000 (18:14 +0200)
This function can be used to find out the XInput2 device ID
behind a GdkDevice, mostly useful when you need to interact
with say Clutter, or raw libXi calls.

docs/reference/gdk/gdk3-sections.txt
gdk/gdk.symbols
gdk/x11/Makefile.am
gdk/x11/gdkdevice-xi2.c
gdk/x11/gdkdevicemanager-x11.c
gdk/x11/gdkprivate-x11.h
gdk/x11/gdkx.h
gdk/x11/gdkx11device.h [new file with mode: 0644]

index 287599b54bb0ba1fea3f58389ca065bba17224cc..ab5cf98931ca94e5afb4ce456a27c6d9d82062c4 100644 (file)
@@ -928,6 +928,7 @@ GDK_POINTER_TO_XID
 GDK_XID_TO_POINTER
 gdk_x11_lookup_xdisplay
 gdk_x11_get_server_time
+gdk_x11_device_get_id
 gdk_x11_display_get_user_time
 gdk_x11_display_broadcast_startup_message
 gdk_x11_display_get_startup_notification_id
index 239ca4e4abd0c9096f079a2167ece6d4d36a622e..8386bb95e48093d8c8bbcc176abd3e060cea959e 100644 (file)
@@ -513,6 +513,7 @@ gdk_x11_cursor_get_type
 gdk_x11_cursor_get_xcursor
 gdk_x11_cursor_get_xdisplay
 gdk_x11_device_core_get_type
+gdk_x11_device_get_id
 gdk_x11_device_manager_core_get_type
 gdk_x11_device_manager_xi2_get_type
 gdk_x11_device_manager_xi_get_type
index 6e10b494c208f8d0136e3b62b1584a560bfe0a93..bd01d9389e237a38e9d3b17a8b94c0dbd6a56764 100644 (file)
@@ -66,6 +66,7 @@ libgdkinclude_HEADERS =       \
 libgdkx11include_HEADERS =     \
        gdkx11applaunchcontext.h \
        gdkx11cursor.h          \
+       gdkx11device.h          \
        gdkx11device-core.h     \
        gdkx11device-xi.h       \
        gdkx11device-xi2.h      \
index d56f8fa4b9387182f511b3dbfdfd5f282564be6d..b86d80221a1fb3cd0a48d0c7b96fd86f3c702989 100644 (file)
@@ -750,6 +750,14 @@ _gdk_x11_device_xi2_translate_state (XIModifierState *mods_state,
   return state;
 }
 
+gint
+_gdk_x11_device_xi2_get_id (GdkX11DeviceXI2 *device)
+{
+  g_return_val_if_fail (GDK_IS_X11_DEVICE_XI2 (device), 0);
+
+  return device->device_id;
+}
+
 #else /* XINPUT_2 */
 
 static void
index a19a05e065e87b322ca83d0d535b8c2c93a2d43d..4d2ebfc2d69b45cb9b1b934749a52280a3ac74a1 100644 (file)
 #include "gdkinternals.h"
 #include "gdkprivate-x11.h"
 
+/* Defines for VCP/VCK, to be used too
+ * for the core protocol device manager
+ */
+#define VIRTUAL_CORE_POINTER_ID 2
+#define VIRTUAL_CORE_KEYBOARD_ID 3
+
 GdkDeviceManager *
 _gdk_x11_device_manager_new (GdkDisplay *display)
 {
@@ -83,3 +89,42 @@ _gdk_x11_device_manager_new (GdkDisplay *display)
                        "display", display,
                        NULL);
 }
+
+/**
+ * gdk_x11_device_get_id:
+ * @device: a #GdkDevice
+ *
+ * Returns the device ID as seen by XInput2.
+ *
+ * <note>
+ *   If gdk_disable_multidevice() has been called, this function
+ *   will respectively return 2/3 for the core pointer and keyboard,
+ *   (matching the IDs for the Virtual Core Pointer and Keyboard in
+ *   XInput 2), but calling this function on any slave devices (i.e.
+ *   those managed via XInput 1.x), will return 0.
+ * </note>
+ *
+ * Returns: the XInput2 device ID.
+ **/
+gint
+gdk_x11_device_get_id (GdkDevice *device)
+{
+  gint device_id = 0;
+
+  g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
+
+#ifdef XINPUT_2
+  if (GDK_IS_X11_DEVICE_XI2 (device))
+    device_id = _gdk_x11_device_xi2_get_id (GDK_X11_DEVICE_XI2 (device));
+  else
+#endif /* XINPUT_2 */
+    if (GDK_IS_X11_DEVICE_CORE (device))
+      {
+        if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
+          device_id = VIRTUAL_CORE_KEYBOARD_ID;
+        else
+          device_id = VIRTUAL_CORE_POINTER_ID;
+      }
+
+  return device_id;
+}
index 52ff852d5809b41f9059b237f484c2778c87e2a5..cb9b231479f797f2f5764d8d93c86ec166976503 100644 (file)
@@ -252,6 +252,9 @@ guchar * _gdk_x11_device_xi2_translate_event_mask (GdkEventMask     event_mask,
 guint    _gdk_x11_device_xi2_translate_state      (XIModifierState *mods_state,
                                                    XIButtonState   *buttons_state,
                                                    XIGroupState    *group_state);
+gint     _gdk_x11_device_xi2_get_id               (GdkX11DeviceXI2 *device);
+
+
 #endif
 
 void     _gdk_x11_event_translate_keyboard_string (GdkEventKey *event);
index 48207b585d9d00c41e67bac7e9da228004efd8d9..66425c92bc9c16f1f00be18af39d21d26cedfdc3 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <gdk/x11/gdkx11applaunchcontext.h>
 #include <gdk/x11/gdkx11cursor.h>
+#include <gdk/x11/gdkx11device.h>
 #include <gdk/x11/gdkx11device-core.h>
 #include <gdk/x11/gdkx11device-xi.h>
 #include <gdk/x11/gdkx11device-xi2.h>
diff --git a/gdk/x11/gdkx11device.h b/gdk/x11/gdkx11device.h
new file mode 100644 (file)
index 0000000..4a55540
--- /dev/null
@@ -0,0 +1,35 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2011 Carlos Garnacho
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (__GDKX_H_INSIDE__) && !defined (GDK_COMPILATION)
+#error "Only <gdk/gdkx.h> can be included directly."
+#endif
+
+#ifndef __GDK_X11_DEVICE_H__
+#define __GDK_X11_DEVICE_H__
+
+#include <gdk/gdk.h>
+
+G_BEGIN_DECLS
+
+gint  gdk_x11_device_get_id  (GdkDevice *device);
+
+G_END_DECLS
+
+#endif /* __GDK_X11_DEVICE_H__ */